<?php
/**
 * Object Relational Persistence Mapping Class for table: medical_agent
 *
 * @package	com.clearhealth
 * @author	ClearHealth Inc.
 */
class MedicalAgent extends ORDataObject {

	/**#@+
	 * Fields of table: medical_agent mapped to class members
	 */
	var $medical_agent_id		= 	'';
	var $vi_name				=	'';
	var $en_name				=	'';
	var $disable 				= 	'';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'medical_agent';

	/**
	 * Primary Key
	 */
	var $_key = 'medical_agent_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'MedicalAgent';

	/**
	 * Handle instantiation
	 */
	function MedicalAgent() {
		parent::ORDataObject();
	}
	
	public function getEnableIssueList() {
		$field	=	L10nHelper::getLocale();
		$field	=	L10nHelper::changeField($field,"name");
		$ds = new Datasource_sql();
		$sql = array(
			'cols' 		=> "medical_agent_id, $field name",
			'from' 		=> "$this->_table",
			'where'		=> "disable = 0"
			);
					
		$ds->setup($this->_db, $sql);
		
		return $ds->toArray('medical_agent_id', 'name');
	}
	
	public function getIssueNameFromId($id) {
		$field	=	L10nHelper::getLocale();
		$field	=	L10nHelper::changeField($field,"name");
		$ds = new Datasource_sql();
		$sql = array(
			'cols' 	=> "$field name",
			'from' 	=> "$this->_table",
		    'where'     => "medical_agent_id = $id"
			);
					
		$ds->setup($this->_db, $sql);
		$item = $ds->toArray();
		return $item[0]['name'];
	}
	
	public function deleteAgent($id) {
		$sql = "delete from $this->_table where $this->_key = $id ";
		$this->_execute($sql);
	}
	
	public function disableAgent($id) {
		$sql = "update $this->_table set disable = 1 where $this->_key = $id ";
		$this->_execute($sql);
		
	}

}
?>

